home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Demos / Bowers Development / AppMaker 2.0b5 / Examples / PowerPlant / OOFILE / CFileAndFindDoc.cp < prev    next >
Encoding:
Text File  |  1995-09-30  |  3.7 KB  |  175 lines  |  [TEXT/MMCC]

  1. // CFileAndFindDoc.cp -- Document methods
  2. // Created 01/01/95 12:01 PM by AppMaker
  3.  
  4. #include "CFileAndFindDoc.h"
  5.  
  6. #include "CListArticles.h"
  7.  
  8. #include <LFile.h>
  9. #include <LPlaceHolder.h>
  10. #include <LPrintout.h>
  11. #include <LWindow.h>
  12. #include <UWindows.h>
  13. #include <String_Utils.h>
  14.  
  15. #include "FileAndFind_OOFILE.h"
  16. #include "CEditArticle.h"
  17. #include "CEditArticle.h"
  18.  
  19. const ResIDT    prto_PrintView        = 201;
  20. const ResIDT    STRx_Untitled        = 128;
  21.  
  22. // ---------------------------------------------------------------------------
  23. //        • CFileAndFindDoc
  24. // ---------------------------------------------------------------------------
  25.  
  26. CFileAndFindDoc::CFileAndFindDoc(
  27.     LCommander    *inSuper)
  28.         : LSingleDoc(inSuper)
  29. , mData(0)
  30. , mArticles(0)
  31. {
  32. }
  33.  
  34. // ---------------------------------------------------------------------------
  35. //        • ~CFileAndFindDoc
  36. // ---------------------------------------------------------------------------
  37. //    Destructor
  38. //
  39.  
  40. CFileAndFindDoc::~CFileAndFindDoc()
  41. {
  42.     delete mData;
  43. delete mArticles;
  44. }
  45.  
  46. //----------
  47. void
  48. CFileAndFindDoc::newFile()
  49. {
  50. FSSpec    fileSpec;
  51. if (AskSaveAs(fileSpec, true)) {
  52. MakeDatabaseObjects();
  53. mData->newConnection(OOF_MacString(fileSpec.name));
  54. CompleteOpenFile(&fileSpec);
  55. }
  56. }
  57.  
  58. //----------
  59. void
  60. CFileAndFindDoc::openFile(
  61.     FSSpec        *inFileSpec)
  62. {
  63. MakeDatabaseObjects();
  64. mData->openConnection(OOF_MacString(inFileSpec->name));
  65. CompleteOpenFile(inFileSpec);
  66. }
  67.  
  68.  
  69.  
  70. // ---------------------------------------------------------------------------
  71. //        • DoPrint
  72. // ---------------------------------------------------------------------------
  73. //    Print the contents of the Document
  74.  
  75. void
  76. CFileAndFindDoc::DoPrint()
  77. {
  78.     LPrintout        *thePrintout = LPrintout::CreatePrintout(prto_PrintView);
  79.     LPlaceHolder    *textPlace = (LPlaceHolder *)
  80.                                     thePrintout->FindPaneByID('TBox');
  81. //!    textPlace->InstallOccupant(mTextView, atNone);
  82.  
  83.  
  84.     thePrintout->DoPrintJob();
  85.     delete thePrintout;
  86. }
  87.  
  88. //----------
  89. Boolean
  90. CFileAndFindDoc::ObeyCommand(
  91.     CommandT    inCommand,
  92.     void        *ioParam)
  93. {
  94.     Boolean        cmdHandled = true;
  95.  
  96.     switch (inCommand) {
  97.  
  98.     // +++ Add cases here for the commands you handle
  99.     //        Remember to add same cases to FindCommandStatus below
  100.     //        to enable/disable the menu items for the commands
  101.  
  102.     default:
  103.             cmdHandled = LSingleDoc::ObeyCommand(inCommand, ioParam);
  104.         break;
  105.     }
  106.  
  107.     return cmdHandled;
  108. }
  109.  
  110. //----------
  111. void
  112. CFileAndFindDoc::FindCommandStatus(
  113.     CommandT    inCommand,
  114.     Boolean        &outEnabled,
  115.     Boolean        &outUsesMark,
  116.     Char16        &outMark,
  117.     Str255        outName)
  118. {
  119.     outUsesMark = false;
  120.  
  121.     switch (inCommand) {
  122.  
  123.     // +++ Add cases here for the commands you handle
  124.  
  125.     default:
  126.             LSingleDoc::FindCommandStatus(inCommand, outEnabled,
  127.                                             outUsesMark, outMark, outName);
  128.         break;
  129.     }
  130. }
  131.  
  132.  
  133. //----------
  134. void
  135. CFileAndFindDoc::MakeDatabaseObjects()
  136. {
  137.  
  138. // MUST TAKE PLACE BEFORE newConnection or openConnection
  139. // you can't define dbTables after opening the connection
  140.  
  141. // Note if these were defined as part of CFIleAndFindDoc, instead of being
  142. // 'newed' heap-based objects, this method would not be necessary
  143.  
  144. mData = new dbConnect_ctree;
  145. // create all database tables
  146. mArticles = new CdbArticles;
  147.  
  148. // change types of files created by c-tree (given modification to ctclib.c)
  149. ctMacCreator = kSignature;
  150. ctMacType = kFileType;
  151. }
  152.  
  153.  
  154. //----------
  155. void
  156. CFileAndFindDoc::CompleteOpenFile(
  157. FSSpec        *inFileSpec)
  158. {
  159.  
  160. // can now make the factories for our database editing windows and dialogs
  161. // which require us to have constructed the database objects
  162.  
  163. AdoptAddDialogFactory(new CEditArticleFactory(this, mArticles));
  164. AdoptEditDialogFactory(new CEditArticleFactory(this, mArticles));
  165. AdoptBrowseWindowFactory(new CListArticlesFactory(this, mArticles));
  166.  
  167. mWindow = MakeBrowser();
  168. if (mWindow != nil) {
  169.     mWindow->SetDescriptor (inFileSpec->name);
  170. }
  171. mIsSpecified = true;
  172.  
  173. }
  174.  
  175.